home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / xmm12.zip / XMS30.DOC < prev   
Text File  |  1992-07-05  |  40KB  |  1,129 lines

  1. eXtended Memory Specification (XMS), version 3.0
  2.  
  3.  
  4. January 1991
  5.  
  6.  
  7. Copyright (c) 1988, Microsoft Corporation, Lotus Development
  8. Corporation, Intel Corporation, and AST Research, Inc.
  9.  
  10. Microsoft Corporation
  11. Box 97017
  12.  
  13. One Microsoft Way
  14. Redmond, WA 98073
  15.  
  16. LOTUS (r)
  17. INTEL (r)
  18. MICROSOFT (r)
  19. AST (r) Research
  20.  
  21. This specification was jointly developed by Microsoft Corporation,
  22. Lotus Development Corporation, Intel Corporation,and AST Research,
  23. Inc. Although it has been released into the public domain and is not
  24. confidential or proprietary, the specification is still the copyright
  25. and property of Microsoft Corporation, Lotus Development Corporation,
  26. Intel Corporation, and AST Research, Inc.
  27.  
  28. Disclaimer of Warranty
  29.  
  30. MICROSOFT CORPORATION, LOTUS DEVELOPMENT CORPORATION, INTEL
  31. CORPORATION, AND AST RESEARCH, INC., EXCLUDE ANY AND ALL IMPLIED
  32. WARRANTIES, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  33. PARTICULAR PURPOSE. NEITHER MICROSOFT NOR LOTUS NOR INTEL NOR AST
  34. RESEARCH MAKE ANY WARRANTY OF REPRESENTATION, EITHER EXPRESS OR
  35. IMPLIED, WITH RESPECT TO THIS SPECIFICATION, ITS QUALITY,
  36. PERFORMANCE, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  37. NEITHER MICROSOFT NOR LOTUS NOR INTEL NOR AST RESEARCH SHALL HAVE ANY
  38. LIABILITY FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
  39. OUT OF OR RESULTING FROM THE USE OR MODIFICATION OF THIS
  40. SPECIFICATION.
  41.  
  42. This specification uses the following trademarks:
  43.  
  44. Intel is a registered trademark of Intel Corporation, Microsoft is a
  45. registered trademark of Microsoft Corporation, Lotus is a registered
  46. trademark of Lotus Development Corporation, and AST is a registered
  47. trademark of AST Research, Inc.
  48.  
  49.  
  50. Extended Memory Specification
  51.  
  52. The purpose of this document is to define the Extended Memory
  53. Specification (XMS) version 3.00 for MS-DOS. XMS allows DOS programs to
  54. utilize additional memory found in Intel's 80286 and 80386 based
  55. machines in a consistent, machine independent manner. With some
  56. restrictions, XMS adds almost 64K to the 640K which DOS programs can
  57. access directly. Depending on available hardware, XMS may provide even
  58. more memory to DOS programs. XMS also provides DOS programs with a
  59. standard method of storing data in extended memory.
  60.  
  61. To be considered fully XMS 3.0 compliant, all calls except those
  62. associated with UMB support must be implemented. UMB functions 10h, 11h
  63. and 12h are optional for XMS 3.0 and may return the Function Not
  64. Implemented error code, 80h.
  65.  
  66. DEFINITIONS:
  67.  
  68. Extended Memory:
  69.  
  70. Memory in 80286 and 80386 based machines which is located above the 1MB
  71. address boundary.
  72.  
  73. High Memory Area (HMA):
  74.  
  75. The first 64K of extended memory.  The High Memory Area is unique
  76. because code can be executed in it while in real mode. The HMA
  77. officially starts at FFFF:10h and ends at FFFF:FFFFh making it 64K-16
  78. bytes in length.
  79.  
  80. Upper Memory Blocks (UMBs):
  81.  
  82. Blocks of memory available on some 80x86 based machines which are
  83. located between DOS's 640K limit and the 1MB address boundary.  The
  84. number, size, and location of these blocks vary widely depending upon
  85. the types of hardware adapter cards installed in the machine.
  86.  
  87. Extended Memory Blocks (EMBs):
  88.  
  89. Blocks of extended memory located above the HMA which can only be used
  90. for data storage.
  91.  
  92. A20 Line:
  93.  
  94. The 21st address line of 80x86 CPUs.  Enabling the A20 line allows
  95. access to the HMA.
  96.  
  97. XMM:
  98.  
  99. An Extended Memory Manager.  A DOS device driver which implements XMS.
  100. XMMs are machine specific but allow programs to use extended memory in a
  101. machine-independent manner.
  102.  
  103. HIMEM.SYS:
  104.  
  105. The Extended Memory Manager currently being distributed by Microsoft.
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. Extended Memory
  119. (Other EMBs could exist above 1088K (1MB+64K)
  120.  
  121.  
  122.  
  123. Top of Memory
  124. High Memory Area (HMA)
  125. 1088K
  126.  
  127.  
  128. Upper Memory Area
  129.  
  130.  
  131. 1024K
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. Conventional or DOS memory
  139.  
  140.  
  141.  
  142.  
  143.  
  144. 640K
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. 0K
  158.  
  159.  
  160. DRIVER INSTALLATION:
  161.  
  162. An XMS driver is installed by including a DEVICE= statement in the
  163. machine's CONFIG.SYS file.It must be installed prior to any other
  164. devices or TSRs which use it.  An optional parameter after the driver's
  165. name (suggested name "/HMAMIN=") indicates the minimum amount of space
  166. in the HMA a program can use.  Programs which use less than the minimum
  167. will not be placed in the HMA.  See "Prioritizing HMA Usage" below for
  168. more information.  A second optional parameter (suggested name
  169. "/NUMHANDLES=") allows users to specify the maximum number of extended
  170. memory blocks which may be allocated at any time.
  171.  
  172. NOTE: XMS requires DOS 3.00 or above.
  173.  
  174.  
  175. THE PROGRAMMING API:
  176.  
  177. The XMS API Functions are accessed via the XMS driver's Control
  178. Function. The address of the Control Function is determined via INT 2Fh.
  179. First, a program should determine if an XMS driver is installed.  Next,
  180. it should retrieve the address of the driver's Control Function.  It can
  181. then use any of the available XMS functions.  The functions are divided
  182. into several groups:
  183.  
  184. 1. Driver Information Functions (0h)
  185. 2. HMA Management Functions (1h-2h)
  186. 3. A20 Management Functions (3h-7h)
  187. 4. Extended Memory Management Functions (8h-Fh)
  188. 5. Upper Memory Management Functions (10h-11h)
  189.  
  190.  
  191. DETERMINING IF AN XMS DRIVER IS INSTALLED:
  192.  
  193. The recommended way of determining if an XMS driver is installed is to
  194. set AH=43h and AL=00h and then execute INT 2Fh.  If an XMS driver is
  195. available, 80h will be returned in AL.
  196.  
  197. Example:
  198.  
  199. ; Is an XMS driver installed?
  200. mov     ax,4300h
  201. int     2Fh         
  202. cmp     al,80h  
  203. jne     NoXMSDriver
  204.  
  205.  
  206. CALLING THE API FUNCTIONS:
  207.  
  208. Programs can execute INT 2Fh with AH=43h and AL=10h to obtain the
  209. address of the driver's control function.  The address is returned in
  210. ES:BX.  This function is called to access all of the XMS functions.  It
  211. should be called with AH set to the number of the API function
  212. requested.  The API function will put a success code of 0001h or 0000h
  213. in AX.  If the function succeeded (AX=0001h), additional information may
  214. be passed back in BX and DX.  If the function failed (AX=0000h), an
  215. error code may be returned in BL.  Valid error codes have their high bit
  216. set.  Developers should keep in mind that some of the XMS API functions
  217. may not be implemented by all drivers and will return failure in all
  218. cases.
  219.  
  220. Example:
  221.  
  222. ; Get the address of the driver's control function
  223. mov     ax,4310h
  224. int     2Fh
  225. mov     word ptr [XMSControl],bx        ; XMSControl is a DWORD
  226. mov     word ptr [XMSControl+2],es
  227.            
  228. ; Get the XMS driver's version number
  229. mov     ah,00h
  230. call    [XMSControl]    ; Get XMS Version Number
  231.  
  232. NOTE: Programs should make sure that at least 256 bytes of stack space
  233. is available before calling XMS API functions.
  234.  
  235.  
  236. API FUNCTION DESCRIPTIONS:
  237.  
  238. The following XMS API functions are available:
  239.  
  240. 0h)  Get XMS Version Number
  241. 1h)  Request High Memory Area
  242. 2h)  Release High Memory Area
  243. 3h)  Global Enable A20
  244. 4h)  Global Disable A20
  245. 5h)  Local Enable A20
  246. 6h)  Local Disable A20
  247. 7h)  Query A20
  248. 8h)  Query Free Extended Memory
  249. 9h)  Allocate Extended Memory Block
  250. Ah)  Free Extended Memory Block
  251. Bh)  Move Extended Memory Block
  252. Ch)  Lock Extended Memory Block
  253. Dh)  Unlock Extended Memory Block
  254. Eh)  Get Handle Information
  255. Fh)  Reallocate Extended Memory Block
  256. 10h)  Request Upper Memory Block
  257. 11h)  Release Upper Memory Block
  258. 12h) Realloc Upper Memory Block
  259. 88h) Query any Free Extended Memory
  260. 89h) Allocate any Extended Memory Block
  261. 8Eh) Get Extended EMB Handle
  262. 8Fh) Realloc any Extended Memory
  263.  
  264. Each is described below.
  265.  
  266.  
  267. Get XMS Version Number (Function 00h):
  268.  
  269.     ARGS:    AH = 00h
  270.     RETS:    AX = XMS version number
  271.         BX = Driver internal revision number
  272.         DX = 0001h if the HMA exists, 0000h otherwise
  273.     ERRS:    None
  274.  
  275. This function returns with AX equal to a 16-bit BCD number representing
  276. the revision of the DOS Extended Memory Specification which the driver
  277. implements (e.g. AX=0235h would mean that the driver implemented XMS
  278. version 2.35). BX is set equal to the driver's internal revision number
  279. mainly for debugging purposes.  DX indicates the existence of the HMA
  280. (not its availability) and is intended mainly for installation programs.
  281.  
  282. NOTE: This document defines version 3.00 of the specification.
  283.  
  284.  
  285. Request High Memory Area (Function 01h):
  286.  
  287.     ARGS:    AH = 01h
  288.          If the caller is a TSR or device driver,
  289.         DX = Space needed in the HMA by the caller in bytes
  290.         If the caller is an application program,
  291.         DX = FFFFh
  292.  
  293.     RETS:    AX = 0001h if the HMA is assigned to the caller, 0000h otherwise
  294.  
  295.         ERRS:     BL = 80h if the function is not implemented
  296.            BL = 81h if a VDISK device is detected
  297.            BL = 90h if the HMA does not exist
  298.            BL = 91h if the HMA is already in use
  299.            BL = 92h if DX is less than the /HMAMIN= parameter
  300.  
  301. This function attempts to reserve the 64K-16 byte high memory area for
  302. the caller.  If the HMA is currently unused, the caller's size parameter
  303. is compared to the /HMAMIN= parameter on the driver's command line. If
  304. the value passed by the caller is greater than or equal to the amount
  305. specified by the driver's parameter, the request succeeds.  This
  306. provides the ability to ensure that programs which use the HMA
  307. efficiently have priority over those which do not.
  308.  
  309. NOTE: See the sections "Prioritizing HMA Usage" and "High Memory Area
  310. Restrictions" below for more information.
  311.  
  312.  
  313. Release High Memory Area (Function 02h):
  314.  
  315.     ARGS:    AH = 02h
  316.  
  317.     RETS:    AX = 0001h if the HMA is successfully released, 0000h otherwise
  318.  
  319.     ERRS:     BL = 80h if the function is not implemented
  320.         BL = 81h if a VDISK device is detected
  321.            BL = 90h if the HMA does not exist
  322.         BL = 93h if the HMA was not allocated
  323.  
  324. This function releases the high memory area and allows other programs to
  325. use it. Programs which allocate the HMA must release it before exiting.
  326. When the HMA has been released, any code or data stored in it becomes
  327. invalid and should not be accessed.
  328.  
  329.  
  330. Global Enable A20 (Function 03h):
  331.  
  332.     ARGS:    AH = 03h
  333.  
  334.     RETS:    AX = 0001h if the A20 line is enabled, 0000h otherwise
  335.  
  336.     ERRS:    BL = 80h if the function is not implemented
  337.         BL = 81h if a VDISK device is detected
  338.         BL = 82h if an A20 error occurs
  339.  
  340. This function attempts to enable the A20 line.  It should only be used
  341. by programs which have control of the HMA. The A20 line should be turned
  342. off via Function 04h (Global Disable A20) before a program releases
  343. control of the system.
  344.  
  345. NOTE: On many machines, toggling the A20 line is a relatively slow operation.
  346.  
  347.  
  348. Global Disable A20 (Function 04h):
  349.  
  350.     ARGS:    AH = 04h
  351.  
  352.     RETS:     AX = 0001h if the A20 line is disabled, 0000h otherwise
  353.  
  354.     ERRS:    BL = 80h if the function is not implemented
  355.         BL = 81h if a VDISK device is detected
  356.         BL = 82h if an A20 error occurs
  357.         BL = 94h if the A20 line is still enabled
  358.  
  359. This function attempts to disable the A20 line.  It should only be used
  360. by programs which have control of the HMA.  The A20 line should be
  361. disabled before a program releases control of the system.
  362.  
  363. NOTE: On many machines, toggling the A20 line is a relatively slow
  364. operation.
  365.  
  366.  
  367. Local Enable A20 (Function 05h):
  368.  
  369.     ARGS:    AH = 05h
  370.  
  371.     RETS:    AX = 0001h if the A20 line is enabled, 0000h otherwise
  372.  
  373.     ERRS:    BL = 80h if the function is not implemented
  374.         BL = 81h if a VDISK device is detected
  375.         BL = 82h if an A20 error occurs
  376.  
  377. This function attempts to enable the A20 line.  It should only be used
  378. by programs which need direct access to extended memory. Programs which
  379. use this function should call Function 06h (Local Disable A20) before
  380. releasing control of the system.
  381.  
  382. NOTE: On many machines, toggling the A20 line is a relatively slow
  383. operation.
  384.  
  385.  
  386. Local Disable A20 (Function 06h):
  387.  
  388.     ARGS:    AH = 06h
  389.  
  390.     RETS:    AX = 0001h if the function succeeds, 0000h otherwise
  391.  
  392.     ERRS:    BL = 80h if the function is not implemented
  393.         BL = 81h if a VDISK device is detected
  394.         BL = 82h if an A20 error occurs
  395.         BL = 94h if the A20 line is still enabled
  396.  
  397. This function cancels a previous call to Function 05h (Local Enable
  398. A20).  It should only be used by programs which need direct access to
  399. extended memory.  Previous calls to Function 05h must be canceled before
  400. releasing control of the system.
  401.  
  402. NOTE: On many machines, toggling the A20 line is a relatively slow operation.
  403.  
  404. Query A20 (Function 07h):
  405.  
  406.     ARGS:    AH = 07h
  407.  
  408.     RETS:    AX = 0001h if the A20 line is physically enabled, 0000h otherwise
  409.  
  410.     ERRS:    BL = 00h if the function succeeds
  411.         BL = 80h if the function is not implemented
  412.         BL = 81h if a VDISK device is detected
  413.  
  414. This function checks to see if the A20 line is physically enabled. It
  415. does this in a hardware independent manner by seeing if "memory wrap"
  416. occurs.
  417.  
  418.  
  419. Query Free Extended Memory (Function 08h):
  420.  
  421.     ARGS:    AH = 08h
  422.  
  423.     RETS:    AX = Size of the largest free extended memory block in K-bytes
  424.         DX = Total amount of free extended memory in K-bytes
  425.  
  426.     ERRS:    BL = 80h if the function is not implemented
  427.         BL = 81h if a VDISK device is detected
  428.         BL = A0h if all extended memory is allocated
  429.  
  430. This function returns the size of the largest available extended memory
  431. block in the system.
  432.  
  433. NOTE: The 64K HMA is not included in the returned value even if it is
  434. not in use.
  435.  
  436.  
  437. Allocate Extended Memory Block (Function 09h):
  438.  
  439.     ARGS:    AH = 09h
  440.         DX = Amount of extended memory being requested in K-bytes
  441.  
  442.     RETS:    AX = 0001h if the block is allocated, 0000h otherwise
  443.         DX = 16-bit handle to the allocated block
  444.  
  445.     ERRS:    BL = 80h if the function is not implemented
  446.         BL = 81h if a VDISK device is detected
  447.         BL = A0h if all available extended memory is allocated
  448.         BL = A1h if all available extended memory handles are in use
  449.  
  450. This function attempts to allocate a block of the given size out of the
  451. pool of free extended memory. If a block is available, it is reserved
  452. for the caller and a 16-bit handle to that block is returned.  The
  453. handle should be used in all subsequent extended memory calls. If no
  454. memory was allocated, the returned handle is null.
  455.  
  456. NOTE: Extended memory handles are scarce resources. Programs should try
  457. to allocate as few as possible at any one time. When all of a driver's
  458. handles are in use, any free extended memory is unavailable.
  459.  
  460. Free Extended Memory Block (Function 0Ah):
  461.  
  462.     ARGS:    AH = 0Ah
  463.         DX = Handle to the allocated block which should be freed
  464.  
  465.     RETS:    AX = 0001h if the block is successfully freed, 0000h otherwise
  466.  
  467.     ERRS:    BL = 80h if the function is not implemented
  468.         BL = 81h if a VDISK device is detected
  469.         BL = A2h if the handle is invalid
  470.         BL = ABh if the handle is locked
  471.  
  472. This function frees a block of extended memory which was previously
  473. allocated using Function 09h (Allocate Extended Memory Block). Programs
  474. which allocate extended memory should free their memory blocks before
  475. exiting. When an extended memory buffer is freed, its handle and all
  476. data stored in it become invalid and should not be accessed.
  477.  
  478.  
  479. Move Extended Memory Block (Function 0Bh):
  480.  
  481.     ARGS:    AH = 0Bh
  482.         DS:SI = Pointer to an Extended Memory Move Structure (see below)
  483.  
  484.     RETS:    AX = 0001h if the move is successful, 0000h otherwise
  485.  
  486.     ERRS:    BL = 80h if the function is not implemented
  487.         BL = 81h if a VDISK device is detected
  488.         BL = 82h if an A20 error occurs
  489.         BL = A3h if the SourceHandle is invalid
  490.         BL = A4h if the SourceOffset is invalid
  491.         BL = A5h if the DestHandle is invalid
  492.         BL = A6h if the DestOffset is invalid
  493.         BL = A7h if the Length is invalid
  494.         BL = A8h if the move has an invalid overlap
  495.         BL = A9h if a parity error occurs
  496.  
  497. Extended Memory Move Structure Definition:
  498.  
  499.         ExtMemMoveStruct    struc
  500.             Length              dd  ?   ; 32-bit number of bytes to transfer
  501.             SourceHandle        dw  ?   ; Handle of source block
  502.             SourceOffset        dd  ?   ; 32-bit offset into source 
  503.             DestHandle          dw  ?   ; Handle of destination block
  504.             DestOffset          dd  ?   ; 32-bit offset into destination block
  505.         ExtMemMoveStruct    ends
  506.             
  507. This function attempts to transfer a block of data from one location to
  508. another. It is primarily intended for moving blocks of data between
  509. conventional memory and extended memory, however it can be used for
  510. moving blocks within conventional memory and within extended memory.
  511.  
  512. NOTE: If SourceHandle is set to 0000h, the SourceOffset is interpreted
  513. as a standard segment:offset air which refers to memory that is directly
  514. accessible by the processor.  The segment:offset pair is stored in Intel
  515. DWORD notation. The same is true for DestHandle and DestOffset.
  516.  
  517.  
  518.    SourceHandle and DestHandle do not have to refer to locked memory
  519.    blocks.
  520.    Length must be even.
  521.    Although not required, WORD-aligned moves can be significantly faster
  522.    on most machines. DWORD aligned move can be even faster on 80386
  523.    machines.
  524.    If the source and destination blocks overlap, only forward moves
  525.    (i.e. where the source base is less than the destination base) are
  526.    guaranteed to work properly.
  527.    Programs should not enable the A20 line before calling this function.
  528.    The state of the A20 line is preserved.
  529.  
  530. This function is guaranteed to provide a reasonable number of  interrupt
  531. windows during long transfers.
  532.  
  533.  
  534. Lock Extended Memory Block (Function 0Ch):
  535.  
  536.     ARGS:    AH = 0Ch
  537.         DX = Extended memory block handle to lock
  538.  
  539.     RETS:    AX = 0001h if the block is locked, 0000h otherwise
  540.         DX:BX = 32-bit physical address of the locked block
  541.  
  542.     ERRS:    BL = 80h if the function is not implemented
  543.         BL = 81h if a VDISK device is detected
  544.         BL = A2h if the handle is invalid
  545.         BL = ACh if the block's lock count overflows
  546.         BL = ADh if the lock fails
  547.  
  548. This function locks an extended memory block and returns its base
  549. address as a 32-bit physical address.  Locked memory blocks are
  550. guaranteed not to move.  The 32-bit pointer is only valid while the
  551. block is locked.Locked blocks should be unlocked as soon as possible.
  552.  
  553. NOTE: A block does not have to be locked before using Function 0Bh (Move
  554. Extended Memory Block). "Lock counts" are maintained for EMBs.
  555.  
  556.  
  557. Unlock Extended Memory Block (Function 0Dh):
  558.  
  559.     ARGS:    AH = 0Dh
  560.         DX = Extended memory block handle to unlock
  561.  
  562.     RETS:    AX = 0001h if the block is unlocked, 0000h otherwise
  563.  
  564.     ERRS:    BL = 80h if the function is not implemented
  565.         BL = 81h if a VDISK device is detected
  566.         BL = A2h if the handle is invalid
  567.         BL = AAh if the block is not locked
  568.     
  569. This function unlocks a locked extended memory block.  Any
  570. 32-bitpointers into the block become invalid and should no longer be
  571. used.
  572.  
  573.  
  574. Get EMB Handle Information (Function 0Eh):
  575.  
  576.     ARGS:    AH = 0Eh
  577.         DX = Extended memory block handle
  578.     RETS:    AX = 0001h if the block's information is found, 0000h otherwise
  579.         BH = The block's lock count
  580.         BL = Number of free EMB handles in the system
  581.         DX = The block's length in K-bytes
  582.  
  583.     ERRS:    BL = 80h if the function is not implemented
  584.         BL = 81h if a VDISK device is detected
  585.         BL = A2h if the handle is invalid
  586.  
  587. This function returns additional information about an extended memory
  588. block to the caller.
  589.  
  590. NOTE: To get the block's base address, use Function 0Ch (Lock Extended
  591. Memory Block).
  592.  
  593.  
  594. Reallocate Extended Memory Block (Function 0Fh):
  595.  
  596.     ARGS:    AH = 0Fh
  597.         BX = New size for the extended memory block in K-bytes
  598.         DX = Unlocked extended memory block handle to reallocate
  599.  
  600.     RETS:    AX = 0001h if the block is reallocated, 0000h otherwise
  601.  
  602.     ERRS:    BL = 80h if the function is not implemented
  603.         BL = 81h if a VDISK device is detected
  604.         BL = A0h if all available extended memory is allocated
  605.         BL = A1h if all available extended memory handles are in use
  606.         BL = A2h if the handle is invalid
  607.         BL = ABh if the block is locked
  608.  
  609. This function attempts to reallocate an unlocked extended memory block
  610. so that it becomes the newly specified size.  If the new size is smaller
  611. than the old block's size, all data at the upper end of the old block is
  612. lost.
  613.  
  614.  
  615. Request Upper Memory Block (Function 10h):
  616.  
  617.     ARGS:    AH = 10h
  618.         DX = Size of requested memory block in paragraphs
  619.  
  620.     RETS:    AX = 0001h if the request is granted, 0000h otherwise
  621.         BX = Segment number of the upper memory block
  622.         If the request is granted,
  623.         DX = Actual size of the allocated block in paragraphs otherwise,
  624.         DX = Size of the largest available UMB in paragraphs
  625.  
  626.     ERRS:    BL = 80h if the function is not implemented
  627.         BL = B0h if a smaller UMB is available
  628.         BL = B1h if no UMBs are available
  629.  
  630. This function attempts to allocate an upper memory block to the caller.
  631. If the function fails, the size of the largest free UMB is returned in
  632. DX.
  633.  
  634. NOTE: By definition UMBs are located below the 1MB address boundary.
  635. The A20 Line does not need to be enabled before accessing an allocated
  636. UMB.
  637.  
  638.    UMBs are paragraph aligned.
  639.    To determine the size of the largest available UMB, attempt to
  640.    allocate one with a size of FFFFh.
  641.    UMBs are unaffected by EMS calls.
  642.  
  643.  
  644. Release Upper Memory Block (Function 11h):
  645.  
  646.     ARGS:    AH = 11h
  647.         DX = Segment number of the upper memory block
  648.  
  649.     RETS:    AX = 0001h if the block was released, 0000h otherwise
  650.  
  651.     ERRS:    BL = 80h if the function is not implemented
  652.         BL = B2h if the UMB segment number is invalid
  653.  
  654. This function frees a previously allocated upper memory block.  When an
  655. UMB has been released, any code or data stored in it becomes invalid and
  656. should not be accessed.
  657.  
  658.  
  659. Reallocate Upper Memory Block (Function 12h)
  660.  
  661.     ARGS:    AH = 12h
  662.         BX = New size for UMB in paragraphs
  663.         DX = Segment number of the UMB to reallocate
  664.  
  665.     RETS:    AX = 1 if the block was reallocated, 0 otherwise
  666.  
  667.     ERRS:    BL = 80h if the function is not implemented
  668.                 BL = B0h if no UMB large enough to satisfy the request
  669.                          is available.
  670.                          In this event, DX is returned with the size of
  671.                          the largest UMB that is available.
  672.                 BL = B2h if the UMB segment number is invalid
  673.  
  674. This function attempts to reallocate an Upper Memory Block to a newly
  675. specified size. If the new size is smaller than the old block's size,
  676. all data at the upper end of the block is lost.
  677.  
  678.  
  679. SUPER EXTENDED MEMORY SUPPORT
  680.  
  681. These changes are intended to provide support for extended memory pools
  682. up to 4 Gb in size. The current XMS API, since it uses 16-bit values to
  683. specify block sizes in Kb, is limited to 64 Mb maximum block size.
  684. Future machines are expected to support memory above 64 MB.
  685.  
  686. This support is implemented in the form of extensions to existing
  687. functions, rather than entirely new entry points, to allow for more
  688. efficient implementations.
  689.  
  690. Programs should generally use the existing functions, instead of these
  691. extended ones, unless they have an explicit need to deal with memory
  692. above 64 Mb.  
  693.  
  694. Query Any Free Extended Memory (Function 88h)
  695.  
  696.     ARGS:    AH = 88h
  697.  
  698.     RETS:    EAX = Size of largest free extended memory block in Kb.
  699.         BL = 0 if no error occurs, otherwise it takes an error code.
  700.         ECX = Highest ending address of any memory block.
  701.         EDX = Total amount of free memory in Kb.
  702.  
  703.     ERRS:    BL = 80h if the function is not implemented.
  704.         BL = 81h if a VDISK device is detected.
  705.         BL = A0h if all extended memory is allocated.
  706.  
  707. This function uses 32-bit values to return the size of available memory,
  708. thus allowing returns up to 4GByte. Additionally, it returns the highest
  709. known physical memory address, that is, the physical address of the last
  710. byte of memory.  There may be discontinuities in the memory map below
  711. this address.
  712.  
  713. The memory pool reported on is the same as that reported on by the
  714. existing Query Free Extended Memory function.  If the highest memory
  715. address is not more than 64 Mb, then these two functions will return the
  716. same results.
  717.  
  718. Because of its reliance on 32-bit registers, this function is only
  719. available on 80386 and higher processors.  XMS drivers on 80286 machines
  720. should return error code 80h if this function is called.
  721.  
  722. If error code 81h is returned, the value in ECX will still be valid.  If
  723. error code A0h is returned, EAX and EDX will be 0, and ECX will still be
  724. valid.
  725.  
  726.  
  727. Allocate Any Extended Memory (Function 89h)
  728.  
  729.     ARGS:    AH = 89h
  730.         EDX = Amount of extended memory requested, in Kb.
  731.  
  732.     RETS:    AX = 1 if the block is allocated, 0 if not
  733.         DX = Handle to allocated block.
  734.  
  735.     ERRS:    BL = 80h if the function is not implemented.
  736.         BL = 81h if a VDISK device is detected.
  737.         BL = A0h if all available extended memory is allocated.
  738.         BL = A1h if all available extended memory handles are in use.
  739.  
  740. This function is similar to the existing Allocate Extended Memory,
  741. except that it uses a 32-bit instead of a 16-bit value to specify the
  742. amount of memory requested.  It allocates from the same memory and
  743. handle pool as the current function.  Since it requires a 32-bit
  744. register, this function can be supported only on 80386 and higher
  745. processors, and XMS drivers on 80286 machines should return error code
  746. 80h.
  747.  
  748. Get Extended EMB Handle Information (Function 8Eh)
  749.  
  750.     ARGS:    AH = 8Eh
  751.         DX = Extended memory block handle.
  752.  
  753.     RETS:    AX = 1 if the block's information is found, 0 if not
  754.         BH = Block lock count
  755.         CX = Number of free EMB handles in the system
  756.         EDX = Block's length in Kb.
  757.  
  758.     ERRS:    BL = 80h if the function is not implemented.
  759.         BL = 81h if a VDISK device is detected.
  760.         BL = A2h if the handle is invalid.
  761.  
  762. This function is similar to the Get EMB Handle Information function.
  763. Since it uses a 32-bit register to report the block size, it can be used
  764. to get information on blocks larger than 64 Mb.  It also uses a 16-bit
  765. instead of 8-bit register to report the number of free handles, allowing
  766. the handle pool to be extended beyond 256 entries.
  767.  
  768. Because of its reliance on a 32-bit register, this function is available
  769. on 80386 and higher processors.  XMS drivers on 80286 machines should
  770. return error code 80h if this function is called.
  771.  
  772.  
  773. Reallocate Any Extended Memory (Function 8Fh)
  774.  
  775.     ARGS:    AH = 8Fh
  776.         EBX = New size for extended memory block, in Kb.
  777.         DX = Unlocked handle for memory block to be resized.
  778.  
  779.     RETS:    AX = 1 if the block is reallocated, 0 if not
  780.  
  781.     ERRS:    BL = 80h if the function is not implemented.
  782.         BL = 81h if a VDISK device is detected.
  783.         BL = A0h if all available extended memory is allocated.
  784.         BL = A1h if all available extended memory handles are in use.
  785.         BL = A2h if the handle is invalid.
  786.         BL = ABh if the block is locked.
  787.  
  788. This function is similar to the existing Reallocate Extended Memory,
  789. except that it uses a 32-bit instead of a 16-bit value to specify the
  790. amount of memory requested.  It allocates from the same memory and
  791. handle pool as the current function.  Since it requires a 32-bit
  792. register, this function can be supported only on 80386 and higher
  793. processors, and XMS drivers on 80286 machines should return error code
  794. 80h.
  795.  
  796.  
  797. PRIORITIZING HMA USAGE:
  798.  
  799. For DOS users to receive the maximum benefit from the High Memory Area,
  800. programs which use the HMA must store as much of their resident code in
  801. it as is possible. It is very important that developers realize that the
  802. HMA is allocated as a single unit. 
  803.  
  804. For example, a TSR program which grabs the HMA and puts 10K of code into
  805. it may prevent a later TSR from putting 62K into the HMA.  Obviously,
  806. regular DOS programs would have more memory available to them below the
  807. 640K line if the 62K TSR was moved into the HMA instead of the 10K one.
  808.  
  809. The first method for dealing with conflicts such as this is to require
  810. programs which use the HMA to provide a command line option for
  811. disabling this feature.  It is crucial that TSRs which do not make full
  812. use of the HMA provide such a switch on their own command line
  813. (suggested name "/NOHMA").
  814.  
  815. The second method for optimizing HMA usage is through the
  816. /HMAMIN=parameter on the XMS device driver line.  The number after the
  817. parameter is defined to be the minimum amount of HMA space (in K-bytes)
  818. used by any driver or TSR. For example, if "DEVICE=HIMEM.SYS /HMAMIN=48"
  819. is in a user's CONFIG.SYS file, only programs which request at least 48K
  820. would be allowed to allocate the HMA.  This number can be adjusted
  821. either by installation programs or by the user himself.  If this
  822. parameter is not specified, the default value of 0 is used causing the
  823. HMA to be allocated on a first come, first served basis.
  824.  
  825. Note that this problem does not impact application programs.  If the HMA
  826. is available when an application program starts, the application is free
  827. to use as much or as little of the HMA as it wants.  For this reason,
  828. applications should pass FFFFh in DX when calling Function 01h.
  829.  
  830.  
  831. HIGH MEMORY AREA RESTRICTIONS:
  832.  
  833.     Far pointers to data located in the HMA cannot be passed to DOS. DOS
  834.     normalizes any pointer which is passed into it. This will cause data
  835.     addresses in the HMA to be invalidated.
  836.  
  837.     Disk I/O directly into the HMA (via DOS, INT 13h, or otherwise) is
  838.     not recommended.
  839.  
  840.     Programs, especially drivers and TSRs, which use the HMA *MUST* use
  841.     as much of it as possible. If a driver or TSR is unable to use at
  842.     least 90% of the available HMA (typically ~58K), they must provide a
  843.     command line switch for overriding HMA usage. This will allow the
  844.     user to configure his machine for optimum use of the HMA.
  845.  
  846.     Device drivers and TSRs cannot leave the A20 line permanently turned
  847.     on. Several applications rely on 1MB memory wrap and will overwrite
  848.     the HMA if the A20 line is left enabled potentially causing a system
  849.     crash.
  850.  
  851.     Interrupt vectors must not point into the HMA.  This is a result of
  852.     the previous restriction. Note that interrupt vectors can point into
  853.     any allocated upper memory blocks however.
  854.  
  855. ERROR CODE INDEX:
  856.  
  857. If AX=0000h when a function returns and the high bit of BL is set,
  858.  
  859. BL=    80h if the function is not implemented
  860.     81h if a VDISK device is detected
  861.     82h if an A20 error occurs
  862.     8Eh if a general driver error occurs
  863.     8Fh if an unrecoverable driver error occurs
  864.     90h if the HMA does not exist
  865.     91h if the HMA is already in use
  866.     92h if DX is less than the /HMAMIN= parameter
  867.     93h if the HMA is not allocated
  868.     94h if the A20 line is still enabled
  869.     A0h if all extended memory is allocated
  870.     A1h if all available extended memory handles are in use
  871.     A2h if the handle is invalid
  872.     A3h if the SourceHandle is invalid
  873.     A4h if the SourceOffset is invalid
  874.         A5h if the DestHandle is invalid
  875.        A6h if the DestOffset is invalid
  876.     A7h if the Length is invalid
  877.     A8h if the move has an invalid overlap
  878.     A9h if a parity error occurs
  879.     AAh if the block is not locked
  880.     ABh if the block is locked
  881.     ACh if the block's lock count overflows
  882.     ADh if the lock fails
  883.     B0h if a smaller UMB is available
  884.     B1h if no UMBs are available
  885.     B2h if the UMB segment number is invalid
  886.  
  887.  
  888. IMPLEMENTATION NOTES FOR DOS XMS DRIVERS:
  889.  
  890.     A DOS XMS driver's control function must begin with code similar to
  891.     the following:
  892.  
  893. XMMControl  proc    far
  894.  
  895.         jmp     short XCControlEntry    ; For "hookability"
  896.         nop                   ; NOTE: The jump must be a short
  897.         nop                 ;  jump to indicate the end of
  898.         nop                 ;  any hook chainThe nop's
  899.                         ;  allow a far jump to be
  900.                         ;  patched in.
  901. XCControlEntry:
  902.  
  903.  
  904.     XMS drivers must preserve all registers except those containing
  905.     returned values across any function call.
  906.  
  907.     XMS drivers are required to hook INT 15h and watch for calls to
  908.     functions 87h (Block Move) and 88h (Extended Memory Available). The
  909.     INT 15h Block Move function must be hooked so that the state of the
  910.     A20 line is preserved across the call. The INT 15h Extended Memory
  911.     Available function must be hooked to return 0h to protect the HMA.
  912.  
  913.     In order to maintain compatibility with existing device drivers, DOS
  914.     XMS drivers must not hook INT 15h until the first non-Version Number
  915.     call to the control function is made.
  916.  
  917.     XMS drivers are required to check for the presence of drivers which
  918.     use the IBM VDISK allocation scheme.  Note that it is not sufficient
  919.     to check for VDISK users at installation time but at the time when
  920.     the HMA is first allocated.  If a VDISK user is detected, the HMA
  921.     must not be allocated. Microsoft will publish a standard method for
  922.     detecting drivers which use the VDISK allocation scheme.
  923.  
  924.     XMS drivers which have a fixed number of extended memory handles
  925.     (most do) should implement a command line parameter for adjusting
  926.     that number (suggested name "/NUMHANDLES=")
  927.  
  928.     XMS drivers should make sure that the major DOS version number is
  929.     greater than or equal to 3 before installing themselves.
  930.  
  931.     UMBs cannot occupy memory addresses that can be banked by EMS
  932.     4.0.EMS 4.0 takes precedence over UMBs for physically addressable
  933.     memory.
  934.  
  935.     All driver functions must be re-entrant.  Care should be taken to
  936.     not leave interrupts disabled for long periods of time.
  937.  
  938.  
  939.     Allocation of a zero length extended memory buffer is allowed.
  940.     Programs which hook XMS drivers may need to reserve a handle for
  941.     private use via this method.  Programs which hook an XMS driver
  942.     should pass all requests for zero length EMBs to the next driver in
  943.     the chain.
  944.  
  945.     Drivers should control the A20 line via an "enable count." Local
  946.     Enable only enables the A20 line if the count is zero.  It then
  947.     increments the count. Local Disable only disables A20 if the count
  948.     is one.  It then decrements the count. Global Enable/Disable keeps a
  949.     flag which indicates the state of A20.  They use Local
  950.     Enable/Disable to actually change the state.
  951.  
  952.     Drivers should always check the physical A20 state in the local
  953.     Enable-Disable calls, to see that the physical state matches the
  954.     internal count.  If the physical state does not match, it should be
  955.     modified so that it matches the internal count.  This avoids
  956.     problems with applications that modify A20 directly.
  957.  
  958.  
  959. IMPLEMENTATION OF CODE FOR HOOKING THE XMS DRIVER:
  960.  
  961. In order to support the hooking of the XMS driver by multiple pieces of
  962. code, the following code sample should be followed. Use of other methods
  963. for hooking the XMS driver will not work in many cases. This method is
  964. the official supported one.
  965.  
  966. The basic strategy is:
  967.  
  968.     Find the XMS driver header which has the "near jump" dispatch.
  969.  
  970.     Patch the near jump to a FAR jump which jumps to my HOOK XMS driver
  971.     header.
  972.  
  973. NOTES:
  974.  
  975.     This architecture allows the most recent HOOKer to undo his XMS
  976.     driver hook at any time without having to worry about damaging a
  977.     "hook chain".
  978.  
  979.     This architecture allows the complete XMS hook chain to be
  980.     enumerated at any time. There are no "hidden hooks".
  981.  
  982.     This architecture allows the HOOKer to not have to worry about
  983.     installing an "INT 2F hook" to hook the AH=43h INT 2Fs handled by
  984.     the XMS driver. The base XMS driver continues to be the only one
  985.     installed on INT 2Fh AH=43h.
  986.  
  987.     This avoids all of the problems of undoing a software interrupt
  988.     hook.
  989.  
  990.   ;
  991.   ; When I wish to CHAIN to the previous XMS driver, I execute a FAR JMP
  992.   ; to the address stored in this DWORD.
  993.   ;
  994.   PrevXMSControlAddr    dd      ?
  995.  
  996.   ;
  997.   ; The next two data items are needed ONLY if I desire to be able to undo
  998.   ; my XMS hook.
  999.   ; PrevXMSControlJmpVal stores the previos XMS dispatch near jump offset
  1000.   ; value that is used to unhook my XMS hook
  1001.   ; PrevXMSControlBase stores the address of the XMS header that I hooked
  1002.   ;
  1003.   PrevXMSControlBase    dd      ?
  1004.   PrevXMSControlJmpVal  db      ?
  1005.  
  1006.   ;
  1007.   ; This is MY XMS control header.
  1008.   ;   MyXMSControlFunc proc FAR
  1009.         jmp     short XMSControlEntry
  1010.         nop
  1011.         nop
  1012.         nop
  1013.   XMSControlEntry:
  1014.  
  1015.   ......
  1016.  
  1017.   Chain:
  1018.         jmp     cs:[PrevXMSControlAddr]
  1019.  
  1020.   MyXMSControlFunc endp
  1021.  
  1022.  
  1023.   .......
  1024.   ;
  1025.   ; This is the code which installs my hook into the XMS driver.
  1026.   ;
  1027.   ;
  1028.   ; See if there is an XMS driver to hook
  1029.   ;
  1030.         mov     ax,4300h
  1031.         int     2Fh
  1032.         cmp     al,80h
  1033.         jne     NoXMSDrvrToHookError
  1034.   ;
  1035.   ; Get the current XMS driver Control address
  1036.   ;
  1037.         mov     ax,4310h
  1038.         int     2Fh
  1039.   NextXMSHeader:
  1040.         mov     word ptr [PrevXMSControlAddr+2],es
  1041.         mov     word ptr [PrevXMSControlBase+2],es
  1042.         mov     word ptr [PrevXMSControlBase],bx
  1043.         mov     cx,word ptr es:[bx]
  1044.         cmp     cl,0EBh                         ; Near JUMP
  1045.         je      ComputeNearJmp
  1046.         cmp     cl,0EAh                         ; Far JUMP
  1047.         jne     XMSDrvrChainMessedUpError
  1048.   ComputeFarJmp:
  1049.         mov     si,word ptr es:[bx+1]           ; Offset of jump
  1050.         mov     es,word ptr es:[bx+1+2]         ; Seg of jump
  1051.         mov     bx,si
  1052.         jmp     short NextXMSHeader
  1053.  
  1054.   ComputeNearJmp:
  1055.         cmp     word ptr es:[bx+2],9090h        ; Two NOPs?
  1056.         jne     XMSDrvrChainMessedUpError       ; No
  1057.         cmp     byte ptr es:[bx+4],90h          ; Total of 3 NOPs?
  1058.         jne     XMSDrvrChainMessedUpError       ; No
  1059.         mov     di,bx                           ; Save pointer to header
  1060.         xor     ax,ax
  1061.         mov     al,ch                           ; jmp addr of near jump
  1062.         mov     [PrevXMSControlJmpVal],al
  1063.         add     ax,2                            ; NEAR JMP is 2 byte instruction
  1064.         add     bx,ax                           ; Target of jump
  1065.         mov     word ptr [PrevXMSControlAddr],bx
  1066.   ;
  1067.   ; Now INSTALL my XMS HOOK
  1068.   ;
  1069.         cli                             ; Disable INTs in case someone calls
  1070.                                         ;       XMS at interrupt time
  1071.         mov     byte ptr es:[di],0EAh   ; Far Immed. JUMP instruction
  1072.         mov     word ptr es:[di+1],offset MyXMSControlFunc
  1073.         mov     word ptr es:[di+3],cs
  1074.         sti
  1075.     .....
  1076.  
  1077.   ;   ; Deinstall my XMS hook. This can be done IF AND ONLY IF my XMS header
  1078.   ;   still contains the near jump dispatch
  1079.   ;
  1080.         cmp     byte ptr [MyXMSControlFunc],0EBh
  1081.         jne     CantDeinstallError
  1082.         mov     al,0EBh
  1083.         mov     ah,[PrevXMSControlJmpVal]
  1084.         les     bx,[PrevXMSControlBase]
  1085.         cli                             ; Disable INTs in case someone calls
  1086.                                         ;       XMS at interrupt time
  1087.         mov     word ptr es:[bx],ax
  1088.         mov     word ptr es:[bx+2],9090h
  1089.         mov     byte ptr es:[bx+4],90h
  1090.         sti
  1091.     ....
  1092.  
  1093.  
  1094. IMPLEMENTATION NOTES FOR HIMEM.SYS:
  1095.  
  1096.     HIMEM.SYS currently supports true AT-compatibles, 386 AT machines,
  1097.     IBM PS/2s, AT&T 6300 Plus systems and Hewlett Packard Vectras.
  1098.  
  1099.     If HIMEM finds that it cannot properly control the A20 line or if
  1100.     there is no extended memory available when HIMEM.SYS is invoked, the
  1101.     driver does not install itself. HIMEM.SYS displays the message "High
  1102.     Memory Area Unavailable" when this situation occurs.
  1103.  
  1104.     If HIMEM finds that the A20 line is already enabled when it is
  1105.     invoked, it will NOT change the A20 line's state.  The assumption is
  1106.     that whoever enabled it knew what they were doing.  HIMEM.SYS
  1107.     displays the message "A20 Line Permanently Enabled" when this
  1108.     situation occurs.
  1109.  
  1110.     HIMEM.SYS is incompatible with IBM's VDISK.SYS driver and other
  1111.     drivers which use the VDISK scheme for allocating extended memory.
  1112.     However,  HIMEM does attempt to detect these drivers and will not
  1113.     allocate the HMA if one is found.
  1114.  
  1115.     HIMEM.SYS supports the optional "/HMAMIN=" parameter.  The valid
  1116.     values are decimal numbers between 0 and 63.
  1117.  
  1118.     By default, HIMEM.SYS has 32 extended memory handles available for
  1119.     use. This number may be adjusted with the "/NUMHANDLES=" parameter.
  1120.     The maximum value for this parameter is 128 and the minimum is 0.
  1121.     Each handle currently requires 6 bytes of resident space.
  1122.  
  1123. Extended Memory Specification (XMS) version 3.0
  1124.  
  1125.  
  1126. Copyright (c) 1988,1992 Microsoft Corporation
  1127.  
  1128.  
  1129.